package com.fancy.learncenter.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.activity.GalleryPicDetailActivity;
import com.fancy.learncenter.activity.ToothDetailsActivity;
import com.fancy.learncenter.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.adapter.base.CustomViewHold;
import com.fancy.learncenter.bean.WDListDataBean;
import com.superservice.lya.R;

import java.io.File;
import java.util.ArrayList;

/**
 * Created by hyy on 2018/1/27.
 * Explain activity as
 */

public class ReleaseWDPIcAdapter extends CommonRecycleViewAdapter<String> {
    public ArrayList<String> itemDatas;

    public ReleaseWDPIcAdapter(Context mContext, ArrayList<String> itemDatas) {
        super(mContext, R.layout.release_pic_item, itemDatas);
        this.itemDatas = itemDatas;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, final String item, final int position) {

        SimpleDraweeView pic = customViewHold.getView(R.id.pic);


        ImageView delete = customViewHold.getView(R.id.delete);
        delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                itemDatas.remove(position);
                notifyDataSetChanged();
            }
        });

        if (position == itemDatas.size() - 1) {
            delete.setVisibility(View.GONE);
            pic.setImageURI(item);
            pic.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (callBack != null) {
                        callBack.OnClick();
                    }

                }
            });
        } else {
            pic.setImageURI("file://" + item);
            delete.setVisibility(View.VISIBLE);

            pic.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    ArrayList itemDatas = new ArrayList();
                    itemDatas.add("file://" + item);
                    Intent intent = new Intent(mContext, GalleryPicDetailActivity.class);
                    intent.putExtra(GalleryPicDetailActivity.PIC_KEY, itemDatas);
                    mContext.startActivity(intent);
                }
            });


        }

    }

    private CallBack callBack;

    public CallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(CallBack callBack) {
        this.callBack = callBack;
    }

    public interface CallBack {
        abstract void OnClick();
    }


}
